package org.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.entity.User;
import org.example.mapper.UserMapper;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    /**
     * @param name
     * @return
     */
    @Override
    public User getUserInfoByName(String name) {

        QueryWrapper<User> wrapper = new QueryWrapper<User>();
        wrapper.eq("name", name);
        User user = userMapper.selectOne(wrapper);

        return user;
    }

    @Override
    public List<String> getUserRoleInfo(String principal) {
        log.info("getUserRoleInfo===============");
        log.info(principal);
        return userMapper.getUserRoleInfoMapper(principal);
    }

    @Override
    public List<String> getUserRolePermissionInfo(String principal) {
        log.info("getUserRolePermissionInfo===============");
        log.info(principal);
        return userMapper.getUserPermissionInfoMapperByPrincipal(principal);
    }

    @Override
    public List<String> getUserRolePermissionInfo(List<String> roles) {
        log.info("getUserRolePermissionInfo===============");
        log.info(roles.toString());
        if(roles.isEmpty()){
            return new ArrayList<>();
        }
        return userMapper.getUserPermissionInfoMapperByRoles(roles);
    }


}
